<?php

namespace App\Http\Requests\Form;

use Illuminate\Contracts\Validation\ValidationRule;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

class PmFormPlanRequest extends FormRequest
{
    /**
     * 表示验证器是否应在第一个规则失败时停止
     *
     * @var bool
     */
    protected $stopOnFirstFailure = true;

    /**
     * Determine if the user is authorized to make this request.
     */
    public function authorize(): bool
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array<string, ValidationRule|array|string>
     */
    public function rules(): array
    {
        return [
            'form_id' => ['required', 'integer', 'min:1', Rule::exists('App\Models\PmForm', 'id')],
            'project_id' => 'required|integer|min:1',   //TODO 需要校验项目ID是否存在
            'end_date' => 'required|date_format:Y-m-d H:i:s',
        ];
    }

    /**
     * 获取已定义验证规则的错误消息
     *
     * @return string[]
     */
    public function messages()
    {
        return [
            'form_id.required' => '表单模版不能为空',
            'form_id.integer' => '表单模版ID必须为一个整数',
            'form_id.min' => '表单模版ID必须为一个大于0的整数',
            'form_id.exists' => '表单模版不存在',
            'project_id.required' => '项目不能为空',
            'project_id.integer' => '项目ID必须为一个整数',
            'project_id.min' => '项目ID必须为一个大于0的整数',
            'end_date.required' => '截止时间不能为空',
            'end_date.date_format' => '截止时间格式错误',
        ];
    }
}
